var editVoucher = {};
var EditVoucher = function () {
    //初始化函数
    this.init = function () {
        //初始化收款账户
        layuiFunciton.selectDict("paymentAccount", "SKZH", $("#paymentAccount").val());
        //收款金额验证
        layuiFunciton.moneyValidation("#paymentAmount");
        //初始化时间控件
        layuiFunciton.layTime({
            elem: '#dateReceipt'
        });
        if ($("#typePayer").val() == 2) {
            //初始化付款单位
            editVoucher.initPaymentUnit();
            $('.paymentUnit').show();
            $("#drawee").attr("readonly", true);
            $(".paymentUnit").find("select").attr("lay-verify", "required");
        }else{
            $(".paymentUnit").hide();
            $("#drawee").removeAttr("readonly");
            $(".paymentUnit").find("select").removeAttr("lay-verify");
        }
        //初始化付款单位
        editVoucher.initPaymentUnit();
    };
    //注册事件
    this.event = function () {
        layuiFunciton.formSubmit({
            filterName: "editVoucher",
            url: layuiFunciton.URL + '/wb/voucher/update',
            formId: "editForm",
            success: function (returnData) {
                if (returnData > 0) {
                    layuiFunciton.success('操作成功！', function () {
                        layuiFunciton.closeOpen();
                    })
                } else {
                    layuiFunciton.warn('操作失败!');
                }
            }
        });
        //类型选择
        layuiFunciton.filter({
            types: 'form',   //   注：仅支持 from 、table 两种类型  监听 table的 tools
            filterTypes: 'select',   //
            filterName: 'typePayerFilter',
            returnData: function (obj) {
                if (obj.value == 2) {
                    //初始化付款单位
                    editVoucher.initPaymentUnit();
                    $('.paymentUnit').show();
                    $("#drawee").attr("readonly", true);
                    $(".paymentUnit").find("select").attr("lay-verify", "required");
                } else {
                    $(".paymentUnit").hide();
                    $("#drawee").removeAttr("readonly");
                    $(".paymentUnit").find("select").removeAttr("lay-verify");
                }
            }
        });
        //付款单位
        layuiFunciton.filter({
            types: 'form',   //   注：仅支持 from 、table 两种类型  监听 table的 tools
            filterTypes: 'select',   //
            filterName: 'paymentUnit',
            returnData: function (obj) {
                if ($("#typePayer").val() == 2) {
                    var text = $("#paymentUnit").find("option:selected").text();
                    if (obj.value) {
                        $("#drawee").val(text);
                    }
                }
            }
        });
    };
    this.initPaymentUnit = function () {
        //初始化付款单位
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode',
            method: 'get',
            maskState: false,
            data: {
                typeCode: "JSR",
                enabled: 1,
                description: '2'
            },
            success: function (data) {
                var optionHtml = '<option value="">请选择</option>';
                data.forEach(function (obj, index) {
                    if (obj.valCode == $("#paymentUnitVal").val()) {
                        optionHtml += '<option value="' + obj.valCode + '" selected>' + obj.valName + '</option>';
                    } else {
                        optionHtml += '<option value="' + obj.valCode + '">' + obj.valName + '</option>';
                    }
                });
                $("#paymentUnit").html(optionHtml);
            }
        })
    };
};
function pageReady() {
    editVoucher = new EditVoucher();
    editVoucher.init();
    editVoucher.event();
}